//
//  ASConfiguration.m
//  Task Views
//
//  Created by Chris Karr on 7/21/09.
//  Copyright 2009 Audacious Software. All rights reserved.
//

#import "ASConfiguration.h"
#import "ConfigManager.h"

@implementation ASConfiguration

- (ASConfiguration *) init
{
	if (self = [self initWithCapacity:2])
	{
		
	}
	
	return self;
}

- (ASConfiguration *) initWithCapacity:(unsigned int) numItems
{
	store = [[NSMutableDictionary alloc] initWithCapacity:numItems];
	
	return self;
}

- (void) setObject:(id) object forKey:(id) key
{
	[self willChangeValueForKey:key];
	
	[store setObject:object forKey:key];
	
	[self didChangeValueForKey:key];
}

- (void) removeObjectForKey:(id) key
{
	[store removeObjectForKey:key];
}

- (unsigned int) count
{
	return [store count];
}

- (id) objectForKey:(id) key
{
	return [store objectForKey:key];
}

- (NSEnumerator *) keyEnumerator
{
	return [store keyEnumerator];
}

- (void) dealloc
{
	[store release];
	
	[super dealloc];
}

- (NSScriptObjectSpecifier *) objectSpecifier 
{
	NSArray * configs = [[NSApp delegate] valueForKey:@"configurations"];
	
    unsigned index = [configs indexOfObject:self];
	
    if (index != NSNotFound) 
	{
		NSScriptObjectSpecifier * containerRef = [NSApp objectSpecifier];
		
        return [[[NSIndexSpecifier alloc] initWithContainerClassDescription:[containerRef keyClassDescription] 
														 containerSpecifier:containerRef key:@"configurations" index:index] autorelease];
    }
	else
        return nil;
}

- (void) activate:(NSScriptCommand *) command
{
	[[NSNotificationCenter defaultCenter] postNotificationName:CONFIG_NOTE object:[self valueForKey:@"source"]];
}

@end
